@echo off
rem Translations of the web portal in windows
rem Created on 22 November 2006
rem Chris Cuthbertson <chris at reeltwo dot com>
rem
rem Requires GetText: http://gnuwin32.sourceforge.net/packages/gettext.htm
rem Assumes Vetech directory structure
rem The variables basedir and gettextdir may require modifying
rem
rem Using tsmarty2c.php, all the {t}tags{/t} are stripped from the smarty
rem templates into vetech.c and converted into messages_<lang>_new.po,
rem then the current language file in \locale\<lang>\LC_MESSAGES\messages.po
rem is merged with the new file into \translate\messages_<lang>.po
rem Optionally, the new messages_<lang>.po can be compiled/moved into
rem messages.mo and messages.po in \locale\<lang>\LC_MESSAGES (messages.po
rem is also backed up to messages.po.backup with only one life)

set basedir=..
set gettextdir=C:\Weida\gettext-tools-0.13.1\bin

if "%1"=="" (
  echo %0 [lang] [compile]
  echo   lang: language to create/merge
  echo   compile: compile the translation
  goto end
)

set outfile=messages_%1_new.po
set mergefile=%basedir%\translate\messages_%1.po
set langdir=%basedir%\locale\%1\LC_MESSAGES
set infile=%langdir%\messages.po

if "%2"=="compile" (
  if not exist %mergefile% (
    echo File to compile not found: %mergefile%
    goto end
  ) else (
    %gettextdir%\msgfmt %mergefile% -o %langdir%\messages.mo
    if exist %infile% copy %infile% %infile%.backup
    copy %mergefile% %infile%
  )
  goto end
)

if exist %infile% (
  copy %infile% %basedir%\translate\%outfile%
) else (
  echo Note: file does not exist: %infile%
)

php %basedir%\translate\tsmarty2c.php %basedir%\templates > %basedir%\translate\pz.c
%gettextdir%\xgettext.exe --no-location -a %basedir%\translate\pz.c --output-dir=%basedir%\translate --output=%outfile%
if exist %infile% (
  %gettextdir%\msgmerge.exe --output-file=%mergefile% %infile% %basedir%\translate\%outfile%
)

:end

